version: "3"

services:
  db:
    container_name: db
    image: postgres:16.0-alpine3.18
    env_file: .env
    volumes:
      - postgres:${PGDATA}
    ports:
      - 5432:5432
    secrets:
      - source: postgres_root_password
    networks:
      - default
    command: postgres -c listen_addresses='*'
    healthcheck:
      test: [ "CMD", "pg_isready" ]
      interval: 1s


  backend:
    container_name: dash-backend
    build:
      context: ./backend
    env_file: .env
    ports:
      - ${SERVER_PORT}:${FORWARDED_PORT}
    secrets:
      - source: postgres_root_password
      - source: secret_key
      - source: admin_initial_password
    networks:
      - default
    depends_on:
      db:
        condition: service_healthy
    stop_grace_period: 1s

  frontend:
    container_name: dash-frontend
    build:
      context: ./frontend
    ports:
      - 3000:3000
    networks:
      - default
    stop_grace_period: 1s

volumes:
  postgres:

secrets:
  postgres_root_password:
    file: .secrets/postgres_root_password
  secret_key:
    file: .secrets/secret_key
  admin_initial_password:
    file: .secrets/admin_initial_password

networks:
  default:
    driver: bridge
